<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/4/20 0020
 * Time: 11:45
 */

namespace App\Controller;

use Hyperf\Di\Annotation\Inject;
use App\Service\UserService;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Request;

class UserController extends BaseController
{

    /**
     * @Inject()
     * @var UserService
     */
    private $userService;

    /**
     * @param RequestInterface $request
     * @return array
     */
    public function getUserInfo(RequestInterface $request)
    {
        $id = $request->input('id', 1);
        $data = $this->userService->getOne($id);
        return $this->success($data, 'success');
    }

    /**
     * 协程查询
     * @return array
     */
    public function getUserList()
    {
        $data = $this->userService->getUserList(['state'=>1]);
        return $this->success($data, 'success');
    }


    public function addUser(Request $request)
    {
        $map = $request->all();
        $map = ['code'=>rand(1000, 9999), 'name'=>'gust'.rand(100, 999), 'state'=>1, 'password'=>'123456'];
        $re = $this->userService->add($map);
        return $this->success($re, 'success');
    }


    /**
     * 更新
     * @param Request $request
     * @return array
     */
    public function updateUser(Request $request)
    {
        $map = $request->all();
        $orm = $this->userService->getOne(1);
        $re = $this->userService->update($orm, ['account'=>'admin111']);
        return $this->success($re, 'success');
    }

}